package com.gk.courses.aspect;

import java.util.Arrays;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class ServiceLoggingAspect {
	
	private static final Log logger = LogFactory.getLog(ServiceLoggingAspect.class);

	@Around("com.gk.courses.aspect.ApplicationPointcut.businessService()")
	public Object doServiceLogging(ProceedingJoinPoint pjp) throws Throwable {
		String pjpToString = pjp.toShortString();
		logger.info("Before method calling " + pjpToString);
		logger.info("Arguments of methods: " + Arrays.asList(pjp.getArgs()));
		Object retVal = pjp.proceed();
		return retVal;
	}

}
